package com.nkym.utils;/*
 * @ClassName ResultUtil
 * @Desc TODO
 * @Author 19637
 * @Date 2023/4/18 21:41
 * @Version 1.0
 */

import com.nkym.common.BaseResponse;
import com.nkym.common.ErrorCode;

public class ResultUtil<T> {
    public static <T> BaseResponse<T> success() {
        return new BaseResponse<T>(0, "success");
    }
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<T>(data,0, "success");
    }
    public static <T> BaseResponse<T> success(String message) {
        return new BaseResponse<T>(null,0, message);
    }
    public static <T> BaseResponse<T> dataOk(T data) {
        return new BaseResponse<T>(data,0, "success");
    }
    public static <T> BaseResponse<T> success(T data,String message) {
        return new BaseResponse<T>(data,0, message);
    }
    public static <T> BaseResponse<T> fail() {
        return new BaseResponse<T>(50001, "system error");
    }
    public static <T> BaseResponse<T> fail(ErrorCode errorCode) {
        return new BaseResponse<T>(errorCode.getCode(), errorCode.getMessage());
    }

    public static <T> BaseResponse<T> fail(T data,String message) {
        return new BaseResponse<T>(data,50001, message);
    }
    public static <T> BaseResponse<T> fail(int code,String message) {
        return new BaseResponse<T>(null,code, message);
    }public static <T> BaseResponse<T> fail(String message) {
        return new BaseResponse<T>(null,50000, message);
    }

}
